export default app => {
  const { STRING, INTEGER, DATE } = app.Sequelize;

  const Image = app.model.define('Image', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: STRING(255),
    fkProduct: {
      type: STRING(36),
      field: 'fk_product',
    },
    createdAt: DATE,
    updatedAt: DATE,
  }, {
    tableName: 'image'
  });

  Image.associate = () => {
    app.model.Image.belongsTo(app.model.Product, {
      foreignKey: 'fk_product',
      targetKey: 'uuid',
    });
  };
  return Image;
};
